package controller;

import com.github.pagehelper.Page;
import io.swagger.models.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import service.FromService;
import tools.PageInvitation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by 14201 on 2019/2/20.
 */
@Controller
@RequestMapping("/ForumInvitation")
public class ForumController {

    @Resource
    FromService fromService;

    @RequestMapping("/list")
    public String getForumList(HttpServletRequest request, @RequestParam(value="chooseId",required=false)Integer chooseId,
                               @RequestParam(value="choose",required=false)String choose, Model model){
        String pageIndex=request.getParameter("pageIndex");
        try {
            int currPageNo = 1;

            if (pageIndex == "" || pageIndex == null) {
                currPageNo = 1;
            } else {
                currPageNo = Integer.parseInt(pageIndex);
            }
            PageInvitation pageObj = new PageInvitation();
            pageObj.setCurrPageNo(currPageNo);
            pageObj.setPageSize(2);
            pageObj = fromService.getForumList(chooseId,choose,pageObj);
            model.addAttribute("page",pageObj);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "index";

    }
}
